package main

// import "fmt"
import (
	"fmt"
	"log"
	"main/cal"
	"main/lession"
	"main/rectangle"
	"main/stringutil"
)

/* 1. package variables */
var rectLength, rectWidth float64 = 6, 7

/*
 * 2. init function to check if length and width are greater than zero
 */
func init() {
	fmt.Println("main package initialized")
	if rectLength < 0 {
		log.Fatal("length is less than zero")
	}
	if rectWidth < 0 {
		log.Fatal("width is less than zero")
	}
}

func main() {
	fmt.Println("hellow world")

	// stringutil 的使用
	fmt.Println(stringutil.Reverse("Hellow, go!"))

	// lession1: 函数
	fmt.Println(lession.CalculateBill(10, 10))

	// cal 引用测试
	result := cal.Add(2, 5)
	fmt.Printf("%d\n", result)

	// lession2: 函数返回值
	var area, perimeter = lession.RectProps(20.4, 30.4)
	fmt.Printf("Area %f Perimeter %f\n", area, perimeter)

	area2, _ := lession.RectProps(10.8, 5.6)
	fmt.Printf("Area %f\n", area2)

	// lession3: init function
	fmt.Println("Geometrical shape properties")
	fmt.Printf("area of rectangle %.2f\n", rectangle.Area(rectLength, rectWidth))
	fmt.Printf("diagonal of the rectangle %.2f ", rectangle.Diagonal(rectLength, rectWidth))

	// lession4: import packages but not use
	var _ = rectangle.Area

	// lession5: if...else
	fmt.Println("奇偶数", lession.IsOdd(44))

	// lession6: Loop
	lession.LoopTest()
	lession.LoopTest2()

	// lession7: switch
	lession.SwitchTest()
	lession.SwitchTest3()

	// lession8: Array
	lession.ArrayTest()

	// lession 7: Slice
	lession.SliceTest()
}
